package com.xm.xmapp.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.xm.xmapp.R;
import com.xm.xmapp.app.CodeConstant;
import com.xm.xmapp.tools.StringTools;

public class SongChePhoneTipDialog extends Dialog {

	private Context context;

	private String time_str, conent_str, phone_str;

	private OnSongChePhoneTipDialog onSongChePhoneTipDialog;

	public interface OnSongChePhoneTipDialog {
		void quxiao();

		void phone();
	}

	public void setOnSongChePhoneTipDialog(
			OnSongChePhoneTipDialog onSongChePhoneTipDialog) {
		this.onSongChePhoneTipDialog = onSongChePhoneTipDialog;
	}

	public SongChePhoneTipDialog(Context context, String time_str,
			String conent_str, String phone_str) {
		super(context, R.style.Dialog);
		// TODO Auto-generated constructor stub
		this.context = context;

		this.conent_str = conent_str;
		this.time_str = time_str;
		this.phone_str = phone_str;

	}

	@SuppressLint("InflateParams")
	public void init() {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.dialog_sendcar_phone_tip, null);

		TextView time, phone, content;
		time = (TextView) view.findViewById(R.id.time);
		phone = (TextView) view.findViewById(R.id.phone);
		content = (TextView) view.findViewById(R.id.content);

		if (time_str != null && !time_str.equals("")) {
			time.setText("服务时间：" + time_str);
		}

		if (phone_str != null && !phone_str.equals("")) {
			// 送车热线：400-186-111
			phone.setText(StringTools.getStyle(5, phone_str, "送车热线："
					+ phone_str));
		} else {
			phone.setText(StringTools.getStyle(5, CodeConstant.phone, "送车热线："
					+ CodeConstant.phone));
		}

		if (conent_str != null && !conent_str.equals("")) {
			// 本次送车将收取您20元服务费!
			content.setText(StringTools.getStyle(8, conent_str + "元",
					"本次送车将收取您" + conent_str + "元" + "服务费!"));
		} else {
			content.setText(StringTools.getStyle(8, "20元", "本次送车将收取您" + "20元"
					+ "服务费!"));
		}

		view.findViewById(R.id.left).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();

						if (onSongChePhoneTipDialog != null)
							onSongChePhoneTipDialog.quxiao();
				
					}
				});

		view.findViewById(R.id.right).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();
						if (onSongChePhoneTipDialog != null)
							onSongChePhoneTipDialog.phone();
						
						if (phone_str != null && !phone_str.equals("")) {
							Intent intent = new Intent(Intent.ACTION_CALL, Uri
									.parse("tel:" + phone_str));
							context.startActivity(intent);
						} else {
							Intent intent = new Intent(Intent.ACTION_CALL, Uri
									.parse("tel:" + CodeConstant.phone));
							context.startActivity(intent);
						}
					}
				});

		setContentView(view);

		Window dialogWindow = getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
		lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
		dialogWindow.setAttributes(lp);
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		super.show();
		/** 3.自动弹出软键盘 **/

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		init();

	}
}
